package com.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.entity.dto.AccountPrivacy;
import com.test.entity.vo.request.AccountPrivacyStatusVo;
import com.test.entity.vo.response.AccountPrivacyVo;
import com.test.mapper.AccountPrivacyMapper;
import com.test.service.AccountPrivacyService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Optional;
@Service
public class AccountPrivacyServiceImpl extends ServiceImpl<AccountPrivacyMapper, AccountPrivacy> implements AccountPrivacyService {

    @Override
    public AccountPrivacyVo getPrivacy(int id) {
        AccountPrivacyVo vo = new AccountPrivacyVo();
        AccountPrivacy privacy = Optional.ofNullable(getOne(new QueryWrapper<AccountPrivacy>().eq("id", id)))
                                    .orElse(new AccountPrivacy(id));
        BeanUtils.copyProperties(privacy,vo);
        return vo;
    }

    @Override
    public void savePrivacy(int id, AccountPrivacyStatusVo vo) {
        AccountPrivacy accountPrivacy = Optional.ofNullable(getOne(new QueryWrapper<AccountPrivacy>().eq("id", id)))
                .orElse(new AccountPrivacy(id));
        String type = vo.getType();
        switch (type){
            case "qq"->{
               accountPrivacy.setQq(vo.getStatus()?1:0);
            }
            case "vx"->{
                accountPrivacy.setVx(vo.getStatus()?1:0);
            }

            case "phone"->{
                accountPrivacy.setPhone(vo.getStatus()?1:0);
            }
            case "email"->{
                accountPrivacy.setEmail(vo.getStatus()?1:0);
            }
            case "gender"->{
                accountPrivacy.setGender(vo.getStatus()?1:0);
            }
        }
        this.saveOrUpdate(accountPrivacy);

    }
}
